package cn.serenedream.housedecoration.dao;

import cn.serenedream.housedecoration.entity.SaleProducts;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SaleProductsRepository extends JpaRepository<SaleProducts, Long> {
    @Modifying
    @Query(value = "delete from sale_products where id = (select sale_products_id from sale_saleproducts where sale_id = :id)", nativeQuery = true)
    void deleteBySaleId(@Param("id") String id);

    // 修改Repository方法，返回列表而不是单个实体
    @Query("SELECT sp FROM SaleProducts sp JOIN SaleSaleProducts ssp ON sp.id = ssp.saleProducts.id WHERE ssp.sale.id = :saleId")
    List<SaleProducts> findBySaleId(@Param("saleId") String saleId);
}
